
#include "r12ds.h"
#include "cmsis_os.h"
#include "user_task.h"


#ifdef DEBUG

CMD_RC_t cmd_rc;

uint8_t sbus_rx_buf[2][RC_FRAME_LENGTH];

#else 

static CMD_RC_t cmd_rc;

#endif

void Task_r12ds(void *argument)
{
   (void)argument;
  const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_R12DS;
    R12ds_DMA_Init(sbus_rx_buf[0],sbus_rx_buf[1],50);
	
      uint32_t tick = osKernelGetTickCount();
   while (1)
   {
#ifdef DEBUG
    task_runtime.stack_water_mark.rs12ds =
        osThreadGetStackSpace(osThreadGetId());
#endif
		 
      if(R12Buf0_WaitDmaCplt(1))
			{
			 sbus_to_rc(sbus_rx_buf[0],&cmd_rc);
				
			}
		  else if(R12Buf1_WaitDmaCplt(1))
				
			{
				sbus_to_rc(sbus_rx_buf[1],&cmd_rc);
			}
//      else 
//      {
//        R12ds_HandleOffline(&cmd_rc);
//      }
      osMessageQueueReset(task_runtime.msgq.cmd.raw.rc);
	    osMessageQueuePut(task_runtime.msgq.cmd.raw.rc,(&cmd_rc),0,0);
	 
	 	tick += delay_tick; /* 计算下一个唤醒时刻*/
		 osDelay(10);
   }



    
 }
